import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { UserWeaponService } from './user-weapon.service';
import { ReqUser } from '../../../common/decorator/user.decorator';
import { PageQuery } from '../../../util/entity/page.entity';
import { UserWeapon } from './entities/user-weapon.entity';

@Controller()
export class UserWeaponController {
  constructor(private readonly userWeaponService: UserWeaponService) {}

  /**
   * 增幅武器
   * @param id
   * @param upType  增幅类型1-正常 2-增幅器
   * @param userId
   */
  @Post('weapon-up/:id')
  weaponUp(
    @Param('id') id: number,
    @Body('upType') upType: number,
    @ReqUser('id') userId: number,
  ) {
    return this.userWeaponService.weaponUp(id, upType, userId);
  }

  /**
   * 用户购买武器
   * @param weaponId
   * @param userId
   */
  @Post('buy/:id')
  buy(@Param('id') weaponId: number, @ReqUser('id') userId: number) {
    return this.userWeaponService.buy(weaponId, userId);
  }

  @Post('list')
  findAll(
    @Body() pageQuery: PageQuery<UserWeapon>,
    @ReqUser('id') userId: number,
  ) {
    return this.userWeaponService.findAll(pageQuery, userId);
  }

  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.userWeaponService.findOneWithWeapon(id);
  }
}
